<?php
//暴露给用户的异常
namespace Modules\Backend\Exceptions;

use Exception;
use Illuminate\Http\Request;

class InvalidRequestException extends Exception
{
    public function __construct(string $message = "", int $code = 400)
    {
        parent::__construct($message, $code);
    }

    public function render(Request $request)
    {
        if ($request->expectsJson()) {
            // json() 方法第二个参数就是 Http 返回码
            return responseExceptionJsonData($this->message,$this->code);
        }
        return view('errors.error', ['msg' => $this->message,'code'=>$this->code]);
    }
}
